#include <stdio.h>
#include <conio.h>
#include <string>
#include <ctype.h>

#define MAX 1000
void xuat_DG_vi_tri_i(int vitridocgia);
char ma_DG[MAX][100];
char hoten_DG[MAX][100];
char CMND_DG[MAX][100];
char namsinh_DG[MAX][100];
char gioitinh_DG[MAX][100];
char email_DG[MAX][100];
char ngaylapthe_DG[MAX][100];
char ngayhethen_DG[MAX][100];
int soluong_DG_HT=0;

void them_DG(int &Soluong_DG)
{
	int i;

	int soluongDG_hientai_tren_mang = soluong_DG_HT;

	printf(" nhap vao so luong doc gia can them ");
	scanf("%d", &Soluong_DG);
	for(i=0;i<Soluong_DG;i++)
	{
		int vitriPhantuvaoMang = i + soluongDG_hientai_tren_mang;

		fflush(stdin);
		printf(" Nhap ma doc gia %d: ",i+1);
		gets(ma_DG[vitriPhantuvaoMang]);
		printf(" Nhap ho va ten doc gia (Yeu cau: chu cai dau viet in Hoa) %d: ",i+1);
		gets(hoten_DG[vitriPhantuvaoMang]);
		printf(" Nhap CMND doc gia %d: ",i+1);
		gets(CMND_DG[vitriPhantuvaoMang]);
		printf(" Nhap ngay thang nam sinh doc gia %d: ",i+1);
		gets(namsinh_DG[vitriPhantuvaoMang]);
		printf(" Nhap gioi tinh doc gia (Nam/Nu) %d: ",i+1);
		gets(gioitinh_DG[vitriPhantuvaoMang]);
		printf(" Nhap email doc gia %d: ",i+1);
		gets(email_DG[vitriPhantuvaoMang]);
		printf(" Nhap ngay lap the cua doc gia %d: ",i+1);
		gets(ngaylapthe_DG[vitriPhantuvaoMang]);
		printf(" Nhap ngay het han cua doc gia %d: ",i+1);
		gets(ngayhethen_DG[vitriPhantuvaoMang]);
		soluong_DG_HT++;
	}
	printf(" Nhap Thanh Cong!! Moi Ban Chon Chuc Nang Tiep Theo !! \n");
}

void xuat_tat_ca_DG()
{
	int i;
	for(i=0;i<soluong_DG_HT;i++)
	{
		printf(" Doc Gia Thu: %d \n",i+1);
		printf(" Ma DG: %s \n",ma_DG[i]);
		printf(" Ten DG: %s \n",hoten_DG[i]);
		printf(" CMND DG: %s \n",CMND_DG[i]);
		printf(" nam sinh DG: %s \n",namsinh_DG[i]);
		printf(" gioi tinh DG: %s \n",gioitinh_DG[i]);
		printf(" email DG: %s \n",email_DG[i]);
		printf(" nhay lap the DG: %s \n",ngaylapthe_DG[i]);
		printf("nhay het han DG: %s \n",ngayhethen_DG[i]);	
	}
}

void Sua_DG_Vi_Tri_Thu_I()
{
	    int i;
	    printf(" Ban muon sua doc gia thu may: ");
	    scanf("%d", &i);

		fflush(stdin);
		if(i<=0 || i > soluong_DG_HT)
		{
			printf("Khong tim thay doc gia ! \n" );
		}
		else
		{
			printf(" Nhap ma doc gia %d ", i );
			gets(ma_DG[i-1]);
			printf(" Nhap ho va ten doc gia (Yeu cau: chu cai dau viet in Hoa) %d: ",i);
			gets(hoten_DG[i-1]);
			printf(" Nhap CMND doc gia %d: ",i);
			gets(CMND_DG[i-1]);
			printf(" Nhap ngay thang nam sinh doc gia %d: ",i);
			gets(namsinh_DG[i-1]);
			printf(" Nhap gioi tinh doc gia (Nam/Nu) %d: ",i);
			gets(gioitinh_DG[i-1]);
			printf(" Nhap email doc gia %d: ",i);
			gets(email_DG[i-1]);
			printf(" Nhap ngay lap the cua doc gia %d: ",i);
			gets(ngaylapthe_DG[i-1]);
			printf(" Nhap ngay het han cua doc gia %d: ",i);
			gets(ngayhethen_DG[i-1]);
		}
}

void xoa_DG_vi_tri_I()
{
	int  i,k;
	printf(" Ban muon xoa doc gia thu may: ");
	scanf("%d",&k);
	if(k<=0 || k > soluong_DG_HT)
	{
		printf("Khong tim thay doc gia ! \n" );
	}
	else 
	{
		for(i=k;i<soluong_DG_HT;i++)
		{
			
			strcpy( ma_DG[i-1],ma_DG[i]);
			strcpy(hoten_DG[i-1] , hoten_DG[i]);
			strcpy(CMND_DG[i-1] , CMND_DG[i]);
			strcpy(namsinh_DG[i-1] , namsinh_DG[i]);
			strcpy(gioitinh_DG[i-1], gioitinh_DG[i]);
			strcpy(email_DG[i-1], email_DG[i]);
			strcpy(ngaylapthe_DG[i-1], ngaylapthe_DG[i]);
			strcpy(ngayhethen_DG[i-1], ngayhethen_DG[i]);
		}
		soluong_DG_HT--;
	}
}

void TK_DG_CMND()
{
	int i; char x[MAX][100];
	fflush(stdin);
	printf(" Nhap vao so CMND nguoi can tim: ");
	gets(x[0]);
	bool cmnd = false;
	int vitricantim = -1;
	for(i=0;i<soluong_DG_HT;i++)
	{

	   if( strcmp(CMND_DG[i],x[0]) == 0)
		{
			vitricantim = i;
			cmnd = true;
			break;
		}
		
	}

	if(cmnd == true)
	{
		printf("Tim Kiem Thanh Cong \n");
		xuat_DG_vi_tri_i(vitricantim);
	}
	else
	{
		printf("khong tim thay \n");
	}

}

void TK_DG_Ten()
{
	int i; char x[MAX][100];
	int mangtim[MAX] ;

	fflush(stdin);
	printf(" Nhap vao ho va ten nguoi can tim: ");
	gets(x[0]);
    int dem = 0; 
	for(i=0;i<soluong_DG_HT;i++)
	{

	   if( strcmp(hoten_DG[i],x[0]) == 0)
		{
			mangtim[dem] = i;
			dem++;
		}
	}
					
	if(dem > 0)
	{
		int phantu;
		printf("Tim Kiem Thanh Cong \n");
		for(phantu = 0; phantu < dem ; phantu++)
		{
			xuat_DG_vi_tri_i(mangtim[phantu]);
		}
	}
	else	
	{
		printf("khong tim thay \n");
	}
}

void TKe_DG()
{
	int i; char x[MAX][100];
	fflush(stdin);
	strcpy(x[0],"Nam");
    int dem = 0; 
	for(i=0;i<soluong_DG_HT;i++)
	{
		
		if( strcmp((gioitinh_DG[i]),x[0]) == 0)
		{
			dem++;
		}
	}

	if(dem > 0)
	{
		printf(" so luong doc gia Nam %d \n",dem);
		printf(" so luong doc gia Nu %d \n",soluong_DG_HT-dem);
	}
	else
	{
		printf(" khong tim thay \n"); 
	}
}


void xuat_DG_vi_tri_i(int vitridocgia)
{
		printf(" Ma DG: %s \n",ma_DG[vitridocgia]);
		printf(" Ten DG: %s \n",hoten_DG[vitridocgia]);
		printf(" CMND DG: %s \n",CMND_DG[vitridocgia]);
		printf(" nam sinh DG: %s \n",namsinh_DG[vitridocgia]);
		printf(" gioi tinh DG: %s \n",gioitinh_DG[vitridocgia]);
		printf(" email DG: %s \n",email_DG[vitridocgia]);
		printf(" ngay lap the DG: %s \n",ngaylapthe_DG[vitridocgia]);
		printf("ngay het han DG: %s \n",ngayhethen_DG[vitridocgia]);
}
